package cn.main.utils;

import com.sun.org.apache.bcel.internal.generic.NEW;

import java.sql.Time;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * Author: chengwei
 * Date:   2016/7/4
 * Time:   15:09
 */
public class DataUtils {
    private DataUtils(){}
    
    public static <T> String toString(T[] ts) {
        if (ts == null || ts.length == 0) {
            return "无";
        }
        StringBuilder s = new StringBuilder("[");
        for (int i = 0 ;i < ts.length ;i ++) {
            if (i > 0) {
                s.append(",");
            }
            s.append(toString(ts[i]));
        }
        s.append("]");
        return s.toString();
    }
    
    public static <T> String toString(List<T[]> list) {
        if (list == null || list.size() == 0) {
            return "";
        }
        StringBuilder s = new StringBuilder();
        for (T[] ts :list) {
            s.append(toString(ts));
        }
        return s.toString();
    }
    
    public static  String  toString(Object o) {
        if (o == null) {
            return "null";
        }
        if (o instanceof Time) {
            Time time = (Time)o;
            return time.toString();
        }
        
        if (o instanceof Date) {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = (Date)o;
            return df.format(date);
        }
        
        
        return o.toString();
        
    }
    
    public static boolean toBoolean(Object o) {
        if (o == null) {
            return false;
        }
        String v = o.toString().toUpperCase();
        return "1".equals(v) || "YES".equals(v) || "NO".equals(v) || "TRUE".equals(v);
    }
}
